package com.example.hadoopdemo.mapreduce;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mrunit.mapreduce.MapDriver;
import org.apache.hadoop.mrunit.mapreduce.ReduceDriver;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Arrays;

/**
 * @author jianwang9@iflytek.com
 * @create 2018-04-02 10:03
 **/
public class MapreduceTest {

    @Test
    public void testMapper() throws IOException {
        String value = "12345678901950234567000353435454354523452345";
        new MapDriver<LongWritable,Text,Text,IntWritable>().withMapper(new MapreduceMapper())
                .withInput(new LongWritable(1),new Text(value)).withOutput(new Text("1950"),new IntWritable(35)).runTest();
    }

    @Test
    public void testReducer() throws IOException {
        new ReduceDriver<Text,IntWritable,Text,IntWritable>()
                .withReducer(new MapreduceReducer())
                .withInput(new Text("1950"), Arrays.asList(new IntWritable(50),new IntWritable(90)))
                .withOutput(new Text("1950"),new IntWritable(90))
                .runTest();
    }
}
